package com.ahau.springcloudHystrix.controller;

import com.ahau.springcloudHystrix.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author xiao hu die
 * @Date 2021/12/19 13:20
 * @Version 1.0
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class PaymentHystrixController {
   @Resource
   private PaymentService paymentService;
   @Value("${server.port}")
   private String serverPort;
   @GetMapping("/hystrix/timeOk/{id}")

    public String timeOk (@PathVariable("id") Integer id){
       String s = paymentService.paymentInfo_OK(id);
       log.info("****************" +s);
       return s;
   }
    @GetMapping("/hystrix/timeOut/{id}")
    public String timeOut (@PathVariable("id") Integer id){
        String s = paymentService.paymentInfo_timeout(id);
        log.info("****************" +s);
        return s;
    }
    @GetMapping("/hystrix/timeOutTest")
    @HystrixCommand
    public String timeOutTest (){
        Integer a= 10;
        Integer b =a/0;
        return "测试方法";
    }
    public String payment_Global_FallbackMethod(){
       return "我是兜底的方法";
    }
 }
